package com.zyh.day03

object GenericTest {
  def main(args: Array[String]): Unit = {
    val p1 = new Pair[String]
    p1.first="hello"
    p1.second="world"
    println(p1)
    println(middle(1, 2, 3))
    println(middle[String]("hello", "world", "baizhi"))
  }
  def middle[T](a:T*): T = {
    a(a.length/2)
  }
}
//将泛型定义在类名后面,作用范围时整个类内部
class Pair[T]{
  var first:T = _
  var second:T = _

  def getFirst(): T = this.first
  def setFirst(first:T): Unit = this.first = first

  override def toString: String = s"$first,$second"
}
